package abq2.jic.jic.plugin.operate.jianli;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;

import kd.bos.dataentity.entity.DynamicObject;
import kd.bos.form.gpt.IGPTAction;


import kd.bos.orm.query.QCP;
import kd.bos.orm.query.QFilter;
import kd.bos.servicehelper.BusinessDataServiceHelper;

import java.util.HashMap;
import java.util.Map;

/**
 * 用于查询工作招聘信息的插件
 */
public class GetJobInfo implements IGPTAction {
    @Override
    public Map<String, String> invokeAction(String action, Map<String, String> params) {
        Map<String , String> result = new HashMap<>();
        //如果操作名称相等
        if ("GET_Job_Info".equalsIgnoreCase(action)) {
            //获取DynamicObject列表，将要获取的字段信息注入
            //将招聘信息的字段加载出来
            DynamicObject[] dys = BusinessDataServiceHelper.load("abq2_recruit",
                    "abq2_title," + //标题内容
                            "billno," +   //单据编号
                            "abq2_address," +  //地址
                            "abq2_exp," +  //经验
                            "abq2_education," +  //学历
                            "abq2_introduction," +  //工作介绍
                            "abq2_job_requirements," +  //工作需求
                            "abq2_salary," +  //薪资
                            "abq2_person_requirements," + //员工需求
                            "abq2_notice," +  //注意事项
                            "abq2_company_name," +  //公司名称
                            "abq2_job_name",  //职位名称
                    (new QFilter("billno", QCP.is_notnull, null)).toArray());
            //创建一个JsonArray，将招聘信息加入到其中
            JSONArray jsonArray = new JSONArray();
            for (DynamicObject dynamicObject : dys) {
                //将每一个书籍的信息加入JSONArray
                JSONObject jsonObject = new JSONObject();
                jsonObject.put("title", dynamicObject.getString("abq2_title"));
                jsonObject.put("address", dynamicObject.getString("abq2_address"));
                jsonObject.put("experience", dynamicObject.getString("abq2_exp"));
                jsonObject.put("education", dynamicObject.getString("abq2_education"));
                jsonObject.put("jobIntroduction", dynamicObject.getString("abq2_introduction"));
                jsonObject.put("jobRequirements",dynamicObject.getString("abq2_job_requirements"));
                jsonObject.put("salary",dynamicObject.getString("abq2_salary"));
                jsonObject.put("personRequirements",dynamicObject.getString("abq2_person_requirements"));
                jsonObject.put("notice",dynamicObject.getString("abq2_notice"));
                jsonObject.put("companyName",dynamicObject.getString("abq2_company_name"));
                jsonObject.put("jobName",dynamicObject.getString("abq2_job_name"));
                jsonArray.add(jsonObject);
            }
            System.out.println(jsonArray.toJSONString());
            //加入resultDynamicObject参数，将JsonArray加入到这个参数当中，然后返回
            result.put("jobInfo", jsonArray.toJSONString());
        }
        return result;
    }
}